import * as Types from '../action-types';


let initState={
    currentLesson:0,
    sliders:[], //轮播图的数据
    lesson:{ //滚动到底部刷新
        lessonList:[],
        hasMore:true, //是否加载更多
        limit:5, //每次想要5条
        offset:0, //偏移量
        isLoading:false //是否正在加载
    }
}
export default function (state=initState,action){
    switch(action.type){
        case Types.SET_CURRENT_LESSON:
            return {
                ...state,currentLesson:action.val,//用新的覆盖掉老的
                lesson:{
                    ...state.lesson,
                    lessonList:[],
                    offset:0
                }
            } 
        case Types.GET_SLIDERS:
            return {...state,sliders:action.sliders}
        case Types.GET_LESSONS:
            return {
                ...state,
                lesson:{
                    ...state.lensson, //lesson中的limit要保留
                    limit:state.lesson.limit,
                    hasMore:action.hasMore,
                    lessonList:[...state.lesson.lessonList,...action.list], //用新的覆盖掉老的
                    offset:state.lesson.offset + action.list.length,
                    isLoading:false //加载完后isLoading变成false
                }
            }
        case Types.SET_LOADING_STATUS:
            return {
                ...state,
                lesson:{
                    ...state.lesson, //把以前的保留
                    isLoading:true //增加的
                }
            }
        default:
            return state;
    }
    
}
